Extended Restore-PnPRecycleBinItem functionality to efficiently restore selected set of items in bulk#4705
Extended Restore-PnPRecycleBinItem functionality to efficiently restore selected set of items in bulk#4705
Conversation
…ing another parameterset for providing an array of Ids of items to restore in bulk. This will allow the users to deal with the scenarios where a lot (but not all) of files need to be restored. Caller can provide a list of Ids of items to bulk restore them. Bulk restore in this case will use REST API to restore items quickly. It also uses a fall back logic to deal with batch errors and automatically switches to individual restore, if needed.
|
Thanks @namwar for your efforts! Looks cool! Left two comments for you. Would appreciate it if you could have a look at those. |
…k to log reasons for failure to restore an item, in case of an error.
|
Please have a look at my comments on your feedback. I have clarified your concern. I think you can merge my code. |
|
Looks good @namwar, thanks! |
|
Still missing your change in the documentation by the way. Can you update Get-PnPRecycleBinItem.md to reflect this new option? |
|
You also don't seem to have checked the option to allow us to update your PR branch so I can add the changelog entry to it. Can you enable that please? |
|
I will update the Get-PnPRecycleBinItem.md quickly |
Added information about the new parameter set. Added example and parameter information.
|
I have updated the documentation/Restore-PnPRecycleBinItem.md. Please have a look. |
|
I had updated the documentation/Restore-PnPRecycleBinItem.md. Please have a look, when you can. |
There was a problem hiding this comment.
Pull Request Overview
Adds bulk restore capability to Restore-PnPRecycleBinItem so multiple specified recycle bin item IDs can be efficiently restored in one operation with REST and fallback to individual restores on failure.
- Introduces new parameter set with IdList (string[]) for bulk restore.
- Implements REST-based batch restore plus fallback logic for per-item restore.
- Updates documentation with new syntax, examples, and parameter details.
Reviewed Changes
Copilot reviewed 3 out of 4 changed files in this pull request and generated 7 comments.
| File | Description |
|---|---|
| src/Commands/Utilities/RecycleBinUtility.cs | Adds bulk restore helper method using REST API with fallback to individual item restoration. |
| src/Commands/RecycleBin/RestoreRecycleBinItem.cs | Adds new parameter set and logic branching for single vs multiple ID restoration. |
| documentation/Restore-PnPRecycleBinItem.md | Updates usage, examples, and parameter documentation to reflect new IdList parameter set. |
| string requestBody = $"{{'ids':['{idsString}']}}"; | ||
| REST.RestHelper.Post(httpClient, apiCall, ctx, requestBody, "application/json", "application/json"); |
There was a problem hiding this comment.
The JSON payload is constructed with single quotes, producing invalid JSON (e.g. {'ids':['id1','id2']}) while the REST call declares application/json. Use double quotes and proper serialization to avoid malformed JSON and escaping issues: var requestBody = JsonConvert.SerializeObject(new { ids = idsList });. Apply the same fix to the fallback block later.
| string requestBody = $"{{'ids':['{id}']}}"; | ||
| REST.RestHelper.Post(httpClient, apiCall, ctx, requestBody, "application/json", "application/json"); |
There was a problem hiding this comment.
Same malformed JSON construction as in the batch request; single quotes produce invalid JSON and unescaped values may break the request if the GUID contains unexpected characters. Replace with JsonConvert.SerializeObject(new { ids = new[]{ id } }) for correctness and safety.
| { | ||
| string requestBody = $"{{'ids':['{idsString}']}}"; | ||
| REST.RestHelper.Post(httpClient, apiCall, ctx, requestBody, "application/json", "application/json"); | ||
| restoreRecycleBinItem.WriteVerbose("Whole batch restored successfuly."); |
There was a problem hiding this comment.
Corrected spelling of 'successfuly' to 'successfully'.
| { | ||
| string requestBody = $"{{'ids':['{id}']}}"; | ||
| REST.RestHelper.Post(httpClient, apiCall, ctx, requestBody, "application/json", "application/json"); | ||
| restoreRecycleBinItem.WriteVerbose($"Item - {id} restored successfuly."); |
There was a problem hiding this comment.
Corrected spelling of 'successfuly' to 'successfully'.
Co-authored-by: Copilot <[email protected]>
Co-authored-by: Copilot <[email protected]>
|
Sorry @namwar for taking so much time to get your PR merged. It's a rather complex one which stalls things from our side. If you're still interested in getting it merged, would you kindly have a look at the merge issues with the current dev branch and resolve these? Thanks! |

Type
What is in this Pull Request ?
Extended the functionality of Restore-PnPRecycleBinItem cmdlet by adding another parameter set. The new parameter set allows the user to provide a string array of Recycle Bin item IDs. It will enable users to deal with scenarios where many (but not all) items need to be restored.
The caller can provide a list of IDs of items to bulk restore them. Bulk restore in this case will use REST API to restore items efficiently, in bulk. It also uses a fallback logic to deal with batch errors and automatically switches to individual restore, if needed.